package com.mj.listen1._06二叉搜索树的重构;

/**
 * 自定义对象
 */
public class Person implements Comparable<Person> {
    private int age;
    private String name;

    public Person(int age) {
        this.age = age;
    }

    public Person(int age, String name) {
        this.age = age;
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public int compareTo(Person e) {
//        if (this.age > e.age) return 1;
//        if (age < e.age) return -1;
//        return 0;
        return age - e.age; // 相当于上面的三行代码
    }

    @Override
    public String toString() {
        return "age=" + age + "name=" + name;
    }
}
